package tsou.cn.glidetest;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {


    private ListView mListview;

    private String[] names = {"解决Glide生成缓存Key问题", "下载&自带动画crossFade", "毛玻璃效果",
            "替换通讯组件为Okhttp加载显示ProgressDialog"
            , "替换通讯组件为Okhttp加载显示ProgressBar", "替换通讯组件为Okhttp加载显示RoundProgressBar",
            "列表显示图片"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initListener();
    }

    private void initView() {
        mListview = (ListView) findViewById(R.id.listview);
        mListview.setAdapter(new MyAdapter());


    }

    private void initListener() {
        mListview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                switch (i) {
                    case 0:
                        startActivity(new Intent(MainActivity.this, UrlHaveTokenActivity.class));
                        break;
                    case 1:
                        startActivity(new Intent(MainActivity.this, CrossFadeActivity.class));
                        break;
                    case 2:
                        startActivity(new Intent(MainActivity.this, FrostedGlassActivity.class));
                        break;
                    case 3:
                        startActivity(new Intent(MainActivity.this, ProgressDialogActivity.class));
                        break;
                    case 4:
                        startActivity(new Intent(MainActivity.this, ProgressBarActivity.class));
                        break;
                    case 5:
                        startActivity(new Intent(MainActivity.this, RoundProgressBarActivity.class));
                        break;
                    case 6:
                        startActivity(new Intent(MainActivity.this, ListActivity.class));
                        break;
                }
            }
        });
    }


    private class MyAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return names.length;
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = null;
            ViewHolder vh;
            if (convertView == null) {
                view = getLayoutInflater().inflate(
                        R.layout.text, parent, false);
                vh = new ViewHolder(view);
                view.setTag(vh);
            } else {
                view = convertView;
                vh = (ViewHolder) view.getTag();
            }
            vh.mTextview.setText(names[position]);
            return view;
        }

        class ViewHolder {
            TextView mTextview;

            ViewHolder(View view) {
                this.mTextview = (TextView) view.findViewById(R.id.textview);
            }
        }
    }


}
